
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/laypage.css">
    <script src="js/vue/vue.min.js"></script>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/laypage/laypage.js" charset="utf-8"></script>
    <script src="js/layer/layer.js" charset="utf-8"></script>
</head>
<body>
<div id="app" class="container">

    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" class="form-control" id="username" placeholder="用户名称">
        </div>
        <div class="form-group">
            <label class="sr-only" for="userage">用户年龄</label>
            <input type="text" class="form-control" id="userage" placeholder="用户电话">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加用户</button>
    </form>


    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>用户</td>
                <td>手机</td>
                <%--<td>角色</td>--%>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.name}}</td>
                <td>{{item.phone}}</td>
                <%--<td>{{item.role}}</td>--%>
                <td>{{item.email}}</td>
                <td><a href="#" @click="editUser(item.id)" >编辑</a> | <a href="#" @click="deleteUser(item.id)">删除</a></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getUserPageList = function (curr) {
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: 'user_queryLikeUsers.action',
            data: {
                curPage: curr || 1,
                perNum: 3,
                name: $("#username").val(),
                phone:$("#userage").val()
            },
            success: function (msg) {
                console.log(msg);
                app.result = msg.userList;
                laypage({
                    cont: 'pagenav',  //存放分页的容器
                    pages: msg.totlePage,  //总页数
                    skin: '#36648B',
                    first: '第一页',
                    last: '最后一页',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getUserPageList(obj.curr);
                        }
                    }
                });
            }
        });
    };

    getUserPageList();


    $("#findUser").click(function () {
        getUserPageList();
    });

    $("#addUserBtn").click(function(){
        layer.open({
         type:2,
        title:'添加用户',
        fix:'false',
        maxmin:true,
        shadeClose:true,
        area:['1100px','600px'],
        content:'addUser.jsp',
         end:function () {
                getUserPageList();
          }

        });
    });
    
    var editUser=function (id) {
       layer.open({
           type: 2,
           title: "编辑用户",
           fix: false,
           maxmin: true,
           shadeClose: true,
           area: ['1100px', '600px'],
           content: 'selectUserById?id=' + id,
           end:function () {
               getUserPageList();
           }
       })
    };

    var deleteUser= function(id){
        layer.confirm("确认删除？", {btn: ["是", "否"]},
            function () {
                $.ajax({
                    type: "GET",
                    url: "deleteUser",
                    data: {
                        id: id
                    },
                    success: function () {
                        getUserPageList();
                        layer.msg("成功删除" + id + "记录", {icon: 6});
                    }
                })
            }, function () {

            });
    }
</script>


</body>
</html>